package com.dykj.fireFighting.web.maintenanceplan;

import java.util.*;

import com.dykj.fireFighting.api.fire.maintenanceplan.entity.RoutineMaintenanceRecord;
import com.dykj.fireFighting.api.fire.maintenanceplan.service.IRoutineMaintenanceRecordService;
import com.dykj.fireFighting.common.core.annotation.AutoLog;
import com.dykj.fireFighting.common.core.api.CommonResult;
import com.dykj.fireFighting.common.core.dto.CommonDto;
import com.dykj.fireFighting.common.core.vo.PageVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;


import javax.validation.Valid;



/**
 * 例行维保记录表接口
 *
 * @Author zly
 * @Date  2021-07-28 15:05:14
 */
@Slf4j
@Api(value = "例行维保记录表接口", tags = {"例行维保记录表接口"})
@RestController
@RequestMapping("personnelstructure/routineMaintenanceRecord")
public class RoutineMaintenanceRecordController {

    @DubboReference
    private IRoutineMaintenanceRecordService routineMaintenanceRecordService;


    /**
     * 例行维保记录表列表
     *
     * @return
     */
    @AutoLog(value = "例行维保记录表-分页列表查询")
    @ApiOperation(value = "例行维保记录表分页列表", notes = "例行维保记录表分页列表")
    @GetMapping("/list")
    @RequiresPermissions("personnelstructure/routineMaintenanceRecord/list")
    public CommonResult<PageVo<RoutineMaintenanceRecord>> treeGrid(CommonDto commonDto) {
        PageVo<RoutineMaintenanceRecord> page = routineMaintenanceRecordService.pageList(commonDto);
        return CommonResult.success(page);
    }

    /**
     * 获取例行维保记录表信息
     */
    @AutoLog(value = "例行维保记录表-获取例行维保记录表信息")
    @ApiOperation(value = "获取例行维保记录表信息", notes = "获取例行维保记录表信息")
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", dataType = "String", required = true)
    @GetMapping("/info/{id}")
    @RequiresPermissions("personnelstructure/routineMaintenanceRecord/info")
    public CommonResult<RoutineMaintenanceRecord> info(@PathVariable("id") String id){
        RoutineMaintenanceRecord routineMaintenanceRecord = routineMaintenanceRecordService.getById(id);
        return CommonResult.success(routineMaintenanceRecord);
    }

    /**
     * 保存例行维保记录表信息
     */
    @AutoLog(value = "例行维保记录表-保存例行维保记录表信息")
    @ApiOperation(value = "保存例行维保记录表信息", notes = "保存例行维保记录表信息")
    @PostMapping("/save")
    @RequiresPermissions("personnelstructure/routineMaintenanceRecord/save")
    public CommonResult save(@Valid @RequestBody RoutineMaintenanceRecord routineMaintenanceRecord) {
        try {
            routineMaintenanceRecord.setCreateTime(new Date());

                routineMaintenanceRecordService.save(routineMaintenanceRecord);
            return CommonResult.success("添加成功");
        } catch (Exception e) {
            log.error(e.getMessage());
            return CommonResult.failed("添加失败，请联系管理员");
        }
    }

    /**
     * 修改例行维保记录表信息
     */
    @AutoLog(value = "例行维保记录表-修改例行维保记录表信息")
    @ApiOperation(value = "修改例行维保记录表信息", notes = "修改例行维保记录表信息")
    @PostMapping("/update")
    @RequiresPermissions("personnelstructure/routineMaintenanceRecord/update")
    public CommonResult update(@Valid @RequestBody RoutineMaintenanceRecord routineMaintenanceRecord) {
        try {

            routineMaintenanceRecordService.updateById(routineMaintenanceRecord);
            return CommonResult.success("修改成功");
        } catch (Exception e) {
            log.error(e.getMessage());
            return CommonResult.failed("添加失败，请联系管理员");
        }
    }

    /**
     * 删除例行维保记录表信息
     */
    @AutoLog(value = "例行维保记录表-删除例行维保记录表信息")
    @ApiOperation(value = "删除例行维保记录表信息", notes = "删除例行维保记录表信息")
    @ApiImplicitParam(paramType = "query", name = "ids", value = "ID数组", dataType = "String", required = true, allowMultiple = true)
    @PostMapping("/delete")
    @RequiresPermissions("personnelstructure/routineMaintenanceRecord/delete")
    public CommonResult delete(@RequestBody String[]ids) {
        try {
                routineMaintenanceRecordService.removeByIds(Arrays.asList(ids));
            return CommonResult.success("删除成功");
        } catch (Exception e) {
            log.error(e.getMessage());
            return CommonResult.failed("添加失败，请联系管理员");
        }
    }
}
